import Vue from 'vue'
import App from './App.vue'
import router from './router'
import 'lib-flexible/flexible.js'
import {setAxiosParam} from './api/iFetch'
import VConsole from 'vconsole' //import vconsole
process.env.NODE_ENV === 'development' ? new VConsole() : "";
// new VConsole()
import {
    Toast,
    Notify,
    Dialog, Button,
    Cell,
    CellGroup,
    Field,
    List,
    Icon,
    Loading,
    Switch,
    Popup,
    PullRefresh
} from 'vant'

Vue.use(Toast)
    .use(Notify)
    .use(Button)
    .use(Dialog)
    .use(Cell)
    .use(CellGroup)
    .use(Field)
    .use(List)
    .use(Icon)
    .use(Loading)
    .use(Switch)
    .use(Popup)
    .use(PullRefresh)

Vue.config.productionTip = false

// 兼容history的路由
if (location.pathname !== '/') {
    location.hash = location.pathname
}

router.beforeEach((to, from, next) => {
    next()
})

//状态翻译
Vue.filter('status', (value: number) => {
    let newValue = ""
    switch (value) {
        case 0:
            newValue = '待确认'; //预发行，待确认
            break
        case 1:
            newValue = '待确认'; //预发行成功，待用户确认
            break
        case 2:
            newValue = '撤销';  //用户点击撤消后的状态
            break
        case 3:
            newValue = '撤消成功';
            break
        case 4:
            newValue = '撤消失败';
            break
        case 5:
            newValue = '待审核';
            break
        case 6:
            newValue = '管理员通过';
            break
        case 7:
            newValue = '管理员拒绝';
            break
        case 8:
            newValue = '发行成功';
            break
        case 9:
            newValue = '发行失败';
            break
        default:
            newValue
    }
    return newValue
},)
//翻译是否可以增发
Vue.filter('category', (value: string) => {
    let newValue = ""
    switch (String(value)) {
        case '0':
            newValue = '不可增发';
            break
        case '1':
            newValue = '可增发';
            break
        default:
            newValue
    }
    return newValue
},)
//token类型
Vue.filter('token_type', (value: string) => {
    const type: any = {
        0: "无",
        1: "商品",
        2: "积分"
    }
    return type[value] || ""
})

//跳转状态页面
Vue.prototype.routerTostatus = (status: string, id?: string, replace: Boolean = true) => {
    let type = ''
    let url = 'status';
    let title = '发布';
    switch (String(status)) {
        //预发行 待确认
        case '0':
            type = 'wait'
            break;
        //预发行成功待用户确认
        case '1':
            type = 'confirm';
            url = 'confirm';
            replace = false;
            break;
        //用户点击撤消后的状态
        case '2':
            type = 'wait'
            break;
        //撤消成功
        case '3':
            type = 'success'
            title = '撤销'
            break;
        //撤消失败
        case '4':
            type = 'fail'
            title = '撤销'
            break
        //用户点击确认后的状态
        case '5':
            type = 'wait'
            break
        //开启人工审核等待
        case '6':
            type = 'wait'
            break
        //管理员拒绝
        case '7':
            type = 'fail'
            break;
        //发行成功
        case '8':
            type = 'success'
            break
        //发行失败
        case '9':
            type = 'fail'
            break;
        default:
            type = 'fail'
    }
    if (!replace) {
        router.push({
            path: url,
            query: {
                type: type,
                id: id || "-1",
                title: title
            }
        })
    } else {
        router.replace({
            path: url,
            query: {
                type: type,
                id: id || "-1",
                title: title
            }
        })
    }
}

//三位一逗号
Vue.filter('NumFormat', function (value: number) {
    if (!value) return '0';
    let intPart = Number(value).toFixed(0);
    return intPart.toString().replace(/(\d)(?=(?:\d{3})+$)/g, '$1,');
})

setAxiosParam().then(() => {
    new Vue({
        router,
        render: (h) => h(App),
    }).$mount('#app')
})

